package com.example.parkdemo.month

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import androidx.recyclerview.widget.LinearLayoutManager
import com.example.base.SelMothResult
import com.example.base.mvvm.BaseActivity
import com.example.base.net.Const
import com.example.parkdemo.R
import com.example.parkdemo.adapter.SelMothAdapter
import com.example.parkdemo.databinding.ActivitySelMonthBinding
import com.google.gson.Gson
import dagger.hilt.android.AndroidEntryPoint
import okhttp3.MediaType.Companion.toMediaTypeOrNull
import okhttp3.RequestBody

@AndroidEntryPoint
class SelMonthActivity : BaseActivity<ActivitySelMonthBinding, selMonthViewModel>() {
    lateinit var selMothAdapter: SelMothAdapter
    override fun initData() {
        val map = mutableMapOf<String, Int>()
        map[Const.PARAM_MONTH] = 1

        val json = Gson().toJson(map)
        val body = RequestBody.create(Const.MEDIA_TYPE.toMediaTypeOrNull(), json)
        vm.month(body)
        vm.monthSuccess.observe(this) {
            val list = Gson().fromJson(it, SelMothResult::class.java)
            selMothAdapter.data.clear()
            selMothAdapter.data.addAll(list)
            selMothAdapter.notifyDataSetChanged()
        }
    }

    override fun initView() {
        binding.selMonthHeader.headerBack.setOnClickListener { finish() }
        binding.selMonthHeader.headerTitle.text = "月度考情"

        selMothAdapter = SelMothAdapter()
        binding.rv.adapter = selMothAdapter
        binding.rv.layoutManager = LinearLayoutManager(this)

    }

}